class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    SetCriterion(item) {
        // 设置检索条件       
        item['Limit'] = parseInt($("#page-size").val());
        item['PageIndex'] = parseInt($("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page"));
        item['OrderBy'] = _Instance.orderby;

        item['Begin'] = formatNullInputValue($.trim($("#Begin").val()));
        item['End'] = formatNullInputValue($.trim($("#End").val()));
        return item;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        // 设置条件
        item = this.SetCriterion(item);

        return JSON.stringify(item);
    }
    FetchByFilter() {
        this.FetchForPage(1);
    }
    FetchAll() {
        $("#Begin").val("");
        $("#End").val("");
        $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", 1);

        this.$pagination.attr("_msh_page", 1);
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        this.$pagination.attr("_msh_page", 1);
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();

        let content_01 = '';
        for (let i = 0; i < result.length; i++) {
            content_01 = '<tr _mash_id="' + result[i].processInstanceId + '" _mash_taskid="' + result[i].taskId + '" _mash_bid="' + result[i].businessKey + '">';
            // content_01 += '<td class="column__action"><span title="编辑" class="edit" onclick="_Instance.DoEdit($(this));"><i class="fa-all fa-pencil fa-1"></i></span></td>';
            if (result[i].assignee === null) {
                content_01 += '<td class="column__action"><span title="签收" class="gridbutton but1" onclick="_Instance.DoClaim($(this));">签收</span></td>';
            } else {
                content_01 += '<td class="column__action"><span title="审批" class="gridbutton but2" onclick="_Instance.DoHandleTask($(this));">审批</span></td>';
            }
            content_01 += '<td class="column__action"><span title="流程图" class="edit" onclick="_Instance.ShowTraceDiagram($(this));"><i class="fa-all fa-info fa-1"></i></span></td>';
            content_01 += '<td>' + formatNullData(result[i].procDefName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].taskName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].startUserName) + '</td>';
            content_01 += '<td style="border-right:none;">' + formatNullData(result[i].createTime) + '</td>';
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
        $('#loading').hide();
    }
    DoInsert() {
        location.assign(parent.basePath + '/oa/todo/1/0/' + 'edit.html');
    }
    DoClaim($self) {
        let variables = {};
        variables['TaskId'] = $self.parent().parent().attr("_mash_taskid");
        variables['UserId'] = parseInt($("#UserId").val());
        super.DoAjax(variables, '/oa/todo/assigneeTask.html', () => {
            this.FetchForPage(this.$pagination.attr("_msh_page"));
        });
    }
    DoHandleTask($self) {
        let _processInstanceId = $self.parent().parent().attr("_mash_id");
        let _taskId = $self.parent().parent().attr("_mash_taskid");
        let _bId = $self.parent().parent().attr("_mash_bid");
        let _taskName = $self.parent().parent().find("td").eq(3).text();
        switch ($self.parent().parent().find("td").eq(2).text()) {
            case "请假申请":
                showModal(900, 520, "请假申请（审批）", parent.basePath + "/hr/leave_application/approve.html?processInstanceId=" + _processInstanceId + "&taskId=" + _taskId + "&bid=" + _bId + "&taskName=" + _taskName, null, function ($dialog) {
                    let _exist = $.inArray($dialog, parent.arrDialog);
                    if (_exist >= 0) {
                        parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
                    }
                });
                break;
        }
    }
    DoEdit($self) {
        // 设置当前检索后的数据列表标识数组
        let _arrayResultList = new Array();
        $("#tabData01 tbody tr").each(function (index) {
            _arrayResultList.push($(this).attr("_mash_id"));
        });
        $.cookie(this.cokieListResult, _arrayResultList.join(","));

        // 在这里判断需要跳转到哪个流程的审批画面
        //location.assign(parent.basePath + '/hr/leave_application/2/' + $self.parent().parent().attr("_mash_id") + '/approve.html');
        location.assign(parent.basePath + '/hr/leave_application/approve.html');
    }
    DoDelete($self) {
        let _params = super.GetFilter(this.$pagination.attr("_msh_page"));
        _params['bulletinId'] = $self.parent().parent().attr("_mash_id");
        _params['deletedBy'] = $("#UserId").val();

        super.DoDelete(_params, function (_this, data) {
            if (data > 0) {
                _Instance.FetchAll();
                ShowSuccessMessagePanel("删除成功。");
            } else {
                // _this.EmptyTableContent();
                ShowErrorMessagePanel('删除不成功。');
            }
        });
    }
    ShowTraceDiagram($self) {
        showModal(1050, 560, "流程状态图", parent.basePath + "/workflow/process_trace/" + $self.parent().parent().attr("_mash_id") + "/diagram.html", null, function ($dialog) {
            let _exist = $.inArray($dialog, parent.arrDialog);
            if (_exist >= 0) {
                parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
            }
        });
    }
    SaveFilters() {
        let _filters = new Array();
        _filters.push($("#Begin").val());
        _filters.push($("#End").val());

        $.cookie("todo_list_fiters", _filters.join(","));
    }
    RestoreFilters() {
        if ($.cookie("todo_list_fiters") !== undefined && this.flag !== 0) {
            let _filters = $.cookie("todo_list_fiters").split(',');
            $("#Begin").val(_filters[0]);
            $("#End").val(_filters[1]);

        } else {
            $("#Begin").val("");
            $("#End").val("");
        }
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let flag = jQuery.url.param("flag") === undefined ? 0 : jQuery.url.param("flag");
    $("#page-size").val($.cookie("todo_list_pagesize") === undefined ? 15 : $.cookie("todo_list_pagesize"));
    // 删除已经保存的检索后的数据列表标识数组
    $.cookie("todo_list_result", null);

    _Instance = new MyPage(0, null, flag,
            $("#page-size"),
            $("abbr.page_indicator_block,#wrapper__navbar"),
            "todo_list_pagesize",
            "todo_list_pageindex",
            "todo_list_result",
            "/oa/todo/fetchTaskForPage.html",
            "");

    //设置分页控制 （操作区域）
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", page);
            _Instance.FetchForPage(page);
        }
    });
    window.laydate.render({
        elem: '#Begin',
        theme: '#393D49',
        trigger: 'click'
    });
    window.laydate.render({
        elem: '#End',
        theme: '#393D49',
        trigger: 'click'
    });

    _Instance.OnPageLoad();
    //$("#loading").hide();
}

function onPageResize() {
}
